package com.situ.crm.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.situ.crm.common.ServerResponse;
import com.situ.crm.entity.CusDevPlan;
import com.situ.crm.entity.Product;
import com.situ.crm.mapper.CusDevPlanMapper;
import com.situ.crm.mapper.ProductMapper;
import com.situ.crm.service.ICusDevPlanService;
import com.situ.crm.service.IProductService;

@Service
public class ProductServiceImpl implements IProductService {

	@Autowired
	private ProductMapper ProductMapper;
	@Override
	public ServerResponse selectProduct() {
		List<Product> list = ProductMapper.selectProduct();
		
		return ServerResponse.createSuccess("成功", list);
	}
	
	@Override
	public ServerResponse pageList(Integer page, Integer limit) {
		//分页
		PageHelper.startPage(page, limit);
		//查询
		List<Product> list = ProductMapper.selectProduct();
		//优化
		PageInfo pageInfo = new PageInfo<>(list);
		Integer count = (int) pageInfo.getTotal();
		
		return ServerResponse.createSuccess("成功", count, list);
	}

	@Override
	public ServerResponse insert(Product product) {
		//调用添加方法
		Integer count = ProductMapper.insertSelective(product);
		System.out.println(count);
		if (count == 1) {
			return ServerResponse.createSuccess("成功");
		}else{
			return ServerResponse.createSuccess("失败");
		} 
	}


}
